import BaseUtil from '@/BaseUtil';
import BuffUtil from '@/BuffUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 连击
 **/
export default class BossSpell_MultiHit extends AbilityBase {
    static instance: BossSpell_MultiHit;
    buffType: AppBuffType = {
        id: 'buff_BossSpell_MultiHit',
        art: this.art,
        name: this.abilityName,
        ubertip: this.ubertip,
        dur: 7,
    };
    constructor(id: string = 'Mzw2') {
        super(id);
        BossSpell_MultiHit.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
        EventManager.onTakeAttack(this.attackEffect.bind(this));
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BossAbilityManagerInstance.text('连击', source);
        BuffUtil.addBuff(source, this.buffType.id, source);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    attackEffect(d: DamageEventData) {
        if (!BuffUtil.hasUnitBuff(d.source, this.buffType.id, d.source)) return;
        if (d.isAttach || GetUnitAbilityLevel(d.source, this.id) == 0) return;
        let m = SLKCommon.getUnitMissileart(d.source);
        let s = SLKCommon.getUnitMissileSpeed(d.source);
        BaseUtil.runLater(0.3, () => {
            MovementCommon.TargetMissile({
                missile: m,
                target: d.target,
                caster: d.source,
                speed: s,
                radian: SLKCommon.getUnitMissilearc(d.source),
                onReach: this.missileReachTarget.bind(this),
            });
        });
    }
    missileReachTarget(p: TargetMissileConfig) {
        DamageSystemInstance.applyAttachAttackDamage(p.target, p.caster, UnitCommon.取攻击(p.caster));
    }
}
